package p2pgame;

import java.io.Serializable;
import java.util.*;

import ludo.Engine;

import rice.p2p.commonapi.Id;

//represents a ludo game in our p2p network.
//has lists of both players and ops.
public class Game implements Serializable{
	final int opsPerGame=5;

	static final long serialVersionUID = 674584476;

	public List<Id> players;
	public List<Id> ops;

	public Id gameId;

	public int turn = 0; //TODO: Maybe move this to ludo`.game?
	public ludo.Engine engine;

	public Game(Id gameId,List<Id> players, List<Id> ops){
		this.gameId=gameId;
		this.engine=new Engine(players.size());
		this.players=players;
		this.ops=ops;
		Collections.sort(this.players, new Comparator<Id>() {
			public int compare(Id a, Id b){
				return a.toStringFull().compareTo(b.toStringFull());
			}
		}
		);
	}

	public Id getPlayerInTurn(){
		return players.get(engine.playerInTurn);
	}
	
	public boolean equals(Game game){
		if (!gameId.equals(game.gameId)) return false;
		if (!players.equals(game.players)) return false;
		if (!ops.equals(game.ops)) return false;
		if (!engine.equals(game.engine)) return false;
		if (!(turn == game.turn)) return false;
		return true;
	}



}